package com.EAIPClub.CodeShellConnecter.config;

import com.EAIPClub.CodeShellConnecter.interceptor.WebSocketInterceptor;
import com.EAIPClub.CodeShellConnecter.websocket.WebSSHWebSocketHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * @Description : WebSSH初始配置类
 * @Author : 崔昌赫
 * @Date : 2021/9/12
 */


@Configuration
@EnableWebSocket
public class WebSSHWebSocketConfig implements WebSocketConfigurer {
    WebSSHWebSocketHandler webSSHWebSocketHandler;

    @Autowired
    public void setWebSSHWebSocketHandler(WebSSHWebSocketHandler webSSHWebSocketHandler) {
        this.webSSHWebSocketHandler = webSSHWebSocketHandler;
    }

    /**
     * @Description : WebSSH初始化类
     * @param  webSocketHandlerRegistry WebSocket注册实例
     * @Author : 崔昌赫
     * @Date : 2021/9/12
     */
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
        //socket通道
        //指定处理器和路径,并设置跨域
        webSocketHandlerRegistry.addHandler(webSSHWebSocketHandler, "/webssh")
                .addInterceptors(new WebSocketInterceptor())
                .setAllowedOrigins("*");

    }
}
